package com.eastfair.venueservice.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.venueservice.dto.*;
import com.eastfair.venueservice.entity.DepositWarning;
import com.eastfair.venueservice.service.DepositWarningService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.DepositWarningVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 前端控制器
 * 押金预警
 * </p>
 *
 * @author linan
 * @date 2023-02-14
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/depositWarning")
@Api(value = "DepositWarning", tags = "押金预警")
@PreAuth(replace = "venueservice:depositWarning:")
public class DepositWarningController extends SuperController<DepositWarningService, Long, DepositWarning, DepositWarningPageQuery, DepositWarningSaveDTO, DepositWarningUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<DepositWarning> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<DepositWarning> depositWarningList = list.stream().map((map) -> {
            DepositWarning depositWarning = DepositWarning.builder().build();
            //TODO 请在这里完成转换
            return depositWarning;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(depositWarningList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<DepositWarningPageQuery> params) {
        DepositWarningPageQuery pageQuery = params.getModel();

    }

    /**
     * 查询押金预警.
     *
     * @param query the query
     * @return the r
     */
    @ApiOperation("查询押金预警.")
    @PostMapping("/queryDepositWarning")
    public R<Page<DepositWarningVO>> queryDepositWarning(@RequestBody PageParams<DepositWarningQuery>  query) {
        log.info("queryDepositWarning - 查询押金预警., query={}", query);
        return R.success(baseService.queryDepositWarning(query));
    }

    /**
     * 修改押金预警.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("修改押金预警.")
    @SysLog("修改押金预警")
    @PostMapping("/updateDepositWarning")
    public R<Boolean> updateDepositWarning(@RequestBody DepositWarningDTO  dto) {
        log.info("updateDepositWarning - 修改押金预警., dto={}", dto);
        return R.success(baseService.updateDepositWarning(dto));
    }

    /**
     * 添加押金预警.
     *
     * @param dto the dto
     * @return the r
     */
    @ApiOperation("添加押金预警.")
    @SysLog("添加押金预警")
    @PostMapping("/addDepositWarning")
    public R<Boolean> addDepositWarning(@RequestBody DepositWarningDTO  dto) {
        log.info("addDepositWarning - 添加押金预警., dto={}", dto);
        return R.success(baseService.addDepositWarning(dto));
    }
}
